<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        class EventCenter {
            constructor() {
                this.eventOpt = {}
            }
            $on(target, handler){
                this.eventOpt[target] = this.eventOpt[target] || []
                this.eventOpt[target].push(handler)
            }
            $emit(eventType) {
                this.eventOpt[eventType] && this.eventOpt[eventType].forEach(handler => {
                    handler()
                })
            }
        }

        let vm = new EventCenter()
        vm.$on('click', () => {
            console.log(1);
        })
        vm.$on('click', () => {
            console.log(2);
        })
        vm.$on('hover', () => {
            console.log(3);
        })
        vm.$emit('click')
    </script>
</body>
</html>